Ext.define('cp.view.form.OsBase',{
    extend: 'Ext.form.Panel',
    
    bodyPadding: '5px 5px 5px 5px', 
    bodyStyle: 'border: none',
    fieldDefaults: {
        labelWidth: 65,
        labelAlign: 'top'
    },
    
    initComponent: function(){
        this.items = [
            {
                bodyStyle: 'border: none',
                layout: 'column',
                items: [
                    {xtype: 'fieldset', defaultType: 'textfield', title: 'Básico', layout: 'column', items:
                        [
                            {xtype: 'fieldset', defaultType: 'textfield', style: 'border: none', items:[
                                { fieldLabel: 'Nombre', name: 'nombre', allowBlank: false, minLength: 4, maxLength: 30, vtype: 'letrasEspacios' },
                                { fieldLabel: 'Domicilio', name: 'domicilio', allowBlank: false, minLength: 9, maxLength: 200, vtype: 'domicilio' },
                                { fieldLabel: 'E-mail', name: 'email', allowBlank: true, vtype: 'email' },
                                { fieldLabel: 'Teléfono', name: 'telefono', allowBlank: true, vtype: 'telefono'},
                            ]}
                        ]
                    }
                ]
              }
         ];    
         
         this.callParent(arguments)
    },
    submitForm: function(){
        if(this.getForm().isValid()){
            this.sendData();
        }else{
            Ext.create('cp.view.ui.AlertErr',{
                mensaje: 'El formulario contiene errores. Por favor, corrigalos, y vuelva a realizar la operación.'
                    }).showDialog();    
        }
    },
    sendData: function(){
        var me = this;
        this.getForm().submit({
            url: me.action,
            method: 'POST',
            success: function(form,action){
                Ext.create('cp.view.ui.AlertOk',{mensaje:action.result.msg}).showDialog();
                me.up('decoratorForm').close();
                Ext.ComponentQuery.query('gestionOs')[0].getStore().load();                 
            },
            failure: function(form, action){
                Ext.create('cp.view.ui.AlertErr',{mensaje:action.result.msg}).showDialog();
            }
        });
    }
});